package com.test.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author ssang
 * @date 2021-12-09 9:20
 */
@Component
public class ApplicationContextUtil implements ApplicationContextAware {

    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

    //获取上下文路径
    public static ApplicationContext getContext(){
        return context;
    }

    //获取bean
    public static Object getBean(String beanName){
        return context.getBean(beanName);
    }
}
